/**
 * Put is a superclass that has Input and Output as subclass.
 * An put has one field, which is a value.
 * 
 * @author Gregory Banfi (gregory.banfi@usi.ch), @author Simone d'Avico (simone.davico@usi.ch); Giuseppe Mendola (giuseppe.mendola@usi.ch);
 * @version 17.05.2011
 */

package ch.usi.inf.pf2.puts;

import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;
import java.util.ArrayList;

import ch.usi.inf.pf2.Component;
import ch.usi.inf.pf2.Value;
import ch.usi.inf.pf2.Wire;
import ch.usi.inf.pf2.pins.InputPin;
import ch.usi.inf.pf2.pins.OutputPin;

public class Put  extends java.awt.Component implements Component, Serializable {

	private ArrayList<Wire> connectedWires;
	private Value value;
	// Fields for the GUI
	private int left;
	private int top;
	private final int width;
	private final int height;
	private ArrayList<Wire> InconnectedWires;
	private ArrayList<Wire> OutconnectedWires;

	/**
	 * Constructor for Put. It assigns a value to the value field of the put
	 * object.
	 * 
	 * @param value
	 *            A value object.
	 */
	public Put(final Value value, final int x, final int y) {
		this.value = value;
		this.left = x;
		this.top = y;
		width = 20;
		height = 20;
		InconnectedWires = new ArrayList<Wire>();
		OutconnectedWires = new ArrayList<Wire>();
	}

	/**
	 * This method returns the value of the put.
	 * 
	 * @return value The value of the put.
	 */
	@Override
	public Value getValue() {
		return value;
	}

	/**
	 * This method set the value of an output.
	 * 
	 * @param value
	 *            A value for the output.
	 */
	@Override
	public void setValue(Value value) {
		this.value = value;
	}

	/**
	 * This method returns the height of the put.
	 * 
	 * @return height The height of the put.
	 */
	public int getHeight() {
		return height;
	}

	/**
	 * This method returns the width of the put.
	 * 
	 * @return width The width of the put.
	 */
	public int getX() {
		return width;
	}

	/**
	 * This method returns the left field of the put.
	 * 
	 * @return left The left field of the put.
	 */
	public int getY() {
		return left;
	}

	/**
	 * This method returns the top field of the put.
	 * 
	 * @return top The top field of the put.
	 */
	public int getWidth() {
		return top;
	}
	
	public void addConnectedWire(Wire wire) {
		connectedWires.add(wire);
	}
	
	public ArrayList<Wire> getConnectedWires() {
		return connectedWires;
	}

	/**
	 * Override methods from component.
	 */
	@Override
	public void add(Component component) {
		// TODO Auto-generated method stub

	}

	@Override
	public void remove(Component component) {
		// TODO Auto-generated method stub
	}

	@Override
	public void draw(Graphics g, Color color) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean contains(int x, int y) {
		return x >= left && x <= left + width + 3 && y >= top
		&& y <= top + height;
	}

	@Override
	public int getOriginX() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getOriginY() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void setInputPins(ArrayList<InputPin> inputPins) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setOutputPin(OutputPin outputPin) {
		// TODO Auto-generated method stub
		
	}
	private int firstPin = 0;
	
	@Override
	public int getFirstFreePin() {
		return firstPin++;
	}
	
	@Override
	public boolean hasFreePins() {
		return (firstPin==0);
	}

	@Override
	public void setOrigin(int x, int y) {
		this.left=x;
		this.top=y;
	}

	@Override
	public void addInConnectedWire(Wire wire) {
		InconnectedWires.add(wire);
	}

	@Override
	public ArrayList<Wire> getInConnectedWires() {
		return InconnectedWires;
	}

	@Override
	public void addOutConnectedWire(Wire wire) {
		OutconnectedWires.add(wire);
	}

	@Override
	public ArrayList<Wire> getOutConnectedWires() {
		return OutconnectedWires;
	}

	@Override
	public ArrayList<InputPin> getInputPins() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public OutputPin compute(ArrayList<InputPin> inputPins) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public OutputPin getOutputPin() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public InputPin getInputPin() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setOutputValue() {
		// TODO Auto-generated method stub
		
	}


}
